home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
archiver
/
unix
/
zip19p1.zoo
/
fileio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-26
|
57KB
|
2,108 lines
/*
Copyright (C) 1990-1992 Mark Adler, Richard B. Wales, Jean-loup Gailly,
Kai Uwe Rommel and Igor Mandrichenko.
Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as all of the original files are included
unmodified, that it is not sold for profit, and that this copyright notice
is retained.
*/
/*
* fileio.c by Mark Adler.
*/
#include "zip.h"
#include <time.h>
#ifdef WIN32
# include <sys/utime.h>
# include <windows.h> /* for findfirst/findnext */
#endif
#ifdef MACOS
# define EXDEV 1
#endif
#ifdef OSF
# define EXDEV 18 /* avoid a bug in the DEC OSF/1 header files. */
#else
# include <errno.h>
#endif
#ifdef MINIX
# ifdef S_IWRITE
# undef S_IWRITE
# endif /* S_IWRITE */
# define S_IWRITE S_IWUSR
#endif /* S_IWUSR */
#ifdef ATARI_ST
# undef MSDOS
#endif
#ifdef MSDOS
# include <io.h>
# if (defined(__TURBOC__) || defined(__GO32__))
# include <dir.h>
# else /* !__TURBOC__ */
# if !defined(__EMX__) && !defined(__WATCOMC__)
# include <direct.h>
# endif
# endif /* ?__TURBOC__ */
# define link rename
# ifdef OS2
# define MATCH shmatch
# else /* !OS2 */
# define MATCH dosmatch
# endif /* ?OS2 */
#else /* !MSDOS */
extern int errno; /* error number from system functions */
# ifdef VMS
# define RMDIR
# define link rename
# include "VMSmunch.h"
# endif /* VMS */
# ifdef MACOS
# define link rename
# define mktemp tmpnam
# endif
# define MATCH shmatch
#endif /* ?MSDOS */
#ifdef ATARI_ST
# define MSDOS 1
#endif
#ifdef UTS
# define RMDIR
#endif /* UTS */
/* Extra malloc() space in names for cutpath() */
#ifdef VMS
# define PAD 3 /* may have to change .FOO] to ]FOO.DIR */
#else /* !VMS */
# define PAD 0
#endif /* ?VMS */
/* For now, assume DIRENT implies System V implies TERMIO */
#if defined(DIRENT) && !defined(MINIX) && !defined(TERMIO)
# define TERMIO
#endif
#ifdef CRYPT
# ifdef MSVMS
# ifdef MSDOS
# ifdef __EMX__
# define getch() _read_kbd(0, 1, 0)
# else
# ifdef __GO32__
# include <pc.h>
# define getch() getkey()
# else
# include <conio.h>
# endif
# endif
# else /* !MSDOS */
# define getch() getc(stderr)
# define echoff(f) echo(0) /* for echo control */
# define echon() echo(1)
# include <iodef.h>
# include <ttdef.h>
# if !defined(SS$_NORMAL)
# define SS$_NORMAL 1 /* only thing we need from <ssdef.h> */
# endif
# endif /* ?MSDOS */
# else /* !MSVMS */
# ifdef TERMIO /* Amdahl, Cray, all SysV? */
# ifdef CONVEX
# include <sys/termios.h>
# include <sgtty.h>
# define O_BINARY 0
# else /* !CONVEX */
# ifdef LINUX
# include <termios.h>
# else /* !LINUX */
# include <sys/termio.h>
# endif /* ?LINUX */
# define sgttyb termio
# define sg_flags c_lflag
int ioctl OF((int, int, voidp *));
# endif /* ?CONVEX */
# define GTTY(f,s) ioctl(f,TCGETA,s)
# define STTY(f,s) ioctl(f,TCSETAW,s)
# else /* !TERMIO */
# ifndef MINIX
# include <sys/ioctl.h>
# endif /* !MINIX */
# include <sgtty.h>
int gtty OF((int, struct sgttyb *));
int stty OF((int, struct sgttyb *));
# define GTTY gtty
# define STTY stty
# endif /* ?TERMIO */
int isatty OF((int));
char *ttyname OF((int));
int open OF((char *, int, ...));
int close OF((int));
int read OF((int, voidp *, int));
# endif /* ?MSVMS */
#endif /* ?CRYPT */
#ifdef VMS
# include <descrip.h>
# include <rms.h>
#endif
/* For directory access. (This is getting rather messy. Cleanup
* scheduled for version 17.9.)
*/
#ifndef UTIL
#ifdef SYSV /* use readdir() */
# include <dirent.h>
# define dstrm DIR
# define direct dirent
#else
#ifdef DIRENT /* use getdents() */
# if defined(MINIX) || defined(OSF)
# include <dirent.h>
# else /* !MINIX */
# include <sys/dirent.h>
# endif /* ?MINIX */
# define direct dirent
# ifdef MINIX
int getdents OF((int, char *, unsigned));
# else /* !MINIX */
int getdents OF((int, char *, int));
# endif /* ?MINIX */
# define DBSZ 4096 /* This has to be bigger than a directory block */
typedef struct { /* directory stream buffer */
int f; /* file descriptor for the directory "file" */
char *p; /* pointer to next entry in buffer */
char *q; /* pointer after end of buffer contents */
char b[DBSZ]; /* buffer */
} dstrm;
#else /* !DIRENT */ /* use opendir(), etc. */
# if defined(CONVEX) || defined(ultrix)
# include <dirent.h>
# ifdef direct
# undef direct /* ultrix 4.2, at least if !__POSIX */
# endif
# define direct dirent
# endif /* CONVEX || ultrix */
# ifdef NDIR
# include "ndir.h" /* for HPUX */
# else /* !NDIR */
# ifdef MSDOS
# ifdef OS2
# include "os2zip.h"
# else /* !OS2 */
# ifndef ATARI_ST
# include <dos.h>
# endif
# if (defined(__TURBOC__) || defined(__GO32__))
# define FATTR FA_HIDDEN+FA_SYSTEM+FA_DIREC
# define FFIRST(n,d) findfirst(n,(struct ffblk *)d,FATTR)
# define FNEXT(d) findnext((struct ffblk *)d)
# else /* !__TURBOC__ */
# define FATTR _A_HIDDEN+_A_SYSTEM+_A_SUBDIR
# define FFIRST(n,d) _dos_findfirst(n,FATTR,(struct find_t *)d)
# define FNEXT(d) _dos_findnext((struct find_t *)d)
# endif /* ?__TURBOC__ */
typedef struct direct {
char d_reserved[30];
char d_name[13];
int d_first;
#ifdef WIN32
HANDLE d_hFindFile;
#endif
} DIR;
# endif /* ?OS2 */
# else /* !MSDOS */
# ifdef VMS
# include <ssdef.h>
typedef struct direct {
int d_wild; /* flag for wildcard vs. non-wild */
struct FAB fab;
struct NAM nam;
char d_qualwildname[NAM$C_MAXRSS + 1];
char d_name[NAM$C_MAXRSS + 1];
} DIR;
# else /* !VMS */
# ifdef MACOS
typedef struct direct {
int d_wild; /* flag for wildcard vs. non-wild */
char *d_name;
} DIR;
# endif
# ifdef M_XENIX
# include <sys/ndir.h>
# else /* !M_XENIX */
# include <sys/dir.h>
# endif /* ?M_XENIX */
# ifdef NODIR /* for AT&T 3B1 */
# define dirent direct
typedef FILE DIR;
# define dstrm DIR
# endif /* NODIR */
# endif /* ?VMS */
# endif /* ?MSDOS */
# endif /* ?NDIR */
# define dstrm DIR
# ifndef NODIR
DIR *opendir OF((char *));
# endif /* !NODIR */
# ifndef CONVEX
struct direct *readdir OF((DIR *));
# endif /* !CONVEX */
#endif /* ?DIRENT */
#endif /* ?SYSV */
#endif /* !UTIL */
/* Library functions not in (most) header files */
#if defined(__IBMC__) || defined(__WATCOMC__)
# define NO_MKTEMP
#endif
char *mktemp OF((char *));
#ifdef __GO32__
char *strlwr OF((char *));
#else
int link OF((char *, char *));
int unlink OF((char *));
# if defined(MSDOS)
int chmod OF((char *, int));
/* For many targets, chmod is already defined by sys/stat.h, and second
* parameter is an unsigned long.
*/
# endif
#endif
#ifndef UTIL /* the companion #endif is a bit of ways down ... */
#ifndef __TURBOC__
int utime OF((char *, time_t *));
#endif /* !__TURBOC__ */
#ifndef MSDOS
int open OF((char *, int, ...));
int close OF((int));
# ifndef RMDIR
int rmdir OF((char *));
# endif /* !RMDIR */
#endif /* !MSDOS */
/* Local globals (kinda like "military intelligence" or "broadcast quality") */
local int exflag = 0; /* Exclude flag */
#ifdef VMS
typedef int statime;
#else /* !VMS */
typedef time_t statime;
#endif /* ?VMS */
/* Local functions */
#ifdef PROTO
# ifdef VMS
local void vms_wild(char *, dstrm *);
# endif /* VMS */
# ifdef DIRENT
local dstrm *opend(char *);
local void close